﻿//************************************************************************************************
// Copyright © 2014 Steven M. Cohn. All Rights Reserved.
// 
//************************************************************************************************

namespace River.Folderize
{
	using System;
	using System.Runtime.InteropServices;
	using System.Text;


	/// <summary>
	/// Native interop declarations.
	/// </summary>
	
	internal static class Native
	{
		public const int LoadLibraryAsDatafile = 0x00000002;

		#region ShellFolderAttributes

		/// <summary>
		/// Description of bit values in the Attributes property of the Registry key
		/// HKEY_CLASSES_ROOT\CLSID\{guid}\ShellFolder.
		/// </summary>

		[Flags]
		public enum ShellFolderAttributes
		{
			CanCopy = 0x00000001,			// Can be copied
			CanMove = 0x00000002,			// Can be moved
			CanLink = 0x00000004,			// Can create shortcuts for item
			Storage = 0x00000008,			// Can be bound to IStorage object
			CanRename = 0x00000010,			// Can be renamed
			CanDelete = 0x00000020,			// Can be deleted
			HasPropSheet = 0x00000040,		// Has property sheets
			DropTarget = 0x00000100,		// Drop target
			System = 0x00001000,			// A system item
			Encrypted = 0x00002000,			// Encrypted and might require special presentation
			IsSlow = 0x00004000,			// Accessing the item expected to be a slow (network)
			Ghosted = 0x00008000,			// Shown as dimmed and unavailable to the user
			Link = 0x00010000,				// Is a shortcut
			Share = 0x00020000,				// Is shared
			ReadOnly = 0x00040000,			// Read-only; only applies to 64-bit OS
			Hidden = 0x00080000,			// Hidden unless Show hidden files option is enabled
			Nonenumerated = 0x00100000,		// Nonenumerated, should be hidden
			NewContent = 0x00200000,		// Contain new content, per some application
			Stream = 0x00400000,			// Has stream associated with it
			StorageAncestor = 0x00800000,	// Children are accessible through IStream or IStorage
			Validate = 0x01000000,			// [in] Validate items in folder exist
			Removable = 0x02000000,			// On removable media or are themselves removable devices
			Compressed = 0x04000000,		// Compressed
			Browsable = 0x08000000,			// Can be hosted inside a web browser or Explorer frame
			FileSysAncestor = 0x10000000,	// File system folder or contains at least one descendant
			Folder = 0x20000000,			// Is a folders
			FileSystem = 0x40000000			// Folders or files are part of the file system
		}
		#endregion ShellFolderAttributes


		[DllImport(
			"shell32.dll", EntryPoint = "ExtractIconA",
			SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true)]
		public static extern IntPtr ExtractIcon (
			int hInst,
			string lpszExeFileName,
			int nIconIndex);


		[DllImport("kernel32.dll", SetLastError = true)]
		public static extern IntPtr LoadLibraryEx (
			string lpFileName,
			IntPtr hFile,
			uint dwFlags);


		[DllImport("user32.dll")]
		public static extern int LoadString (
			IntPtr hInstance,
			int uID,
			StringBuilder lpBuffer,
			int nBufferMax);


		[DllImport("shell32.dll", CharSet = CharSet.Auto)]
		public static extern int PickIconDlg (
			IntPtr hwndOwner,
			StringBuilder lpstrFile,
			int nMaxFile,
			ref int lpdwIconIndex);
	}
}
